package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.VO;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.service.merchant.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
    @Reference
    private IUserService userService;

    @RequestMapping(value = "/getUserInfo", method ={RequestMethod.POST, RequestMethod.GET} )
    @ResponseBody
    public AjaxObject getUserInfo(HttpServletRequest request, HttpServletResponse response,
                                  @RequestParam String userName, @RequestParam String password ){
        try{
            VO vo = userService.getUserInfo(userName, password);
            return AjaxObject.ok().put("data", vo.toHashMap(true));
        } catch (Exception e){
            logger.error("getUserInfo Exception：", e);
            AjaxObject.error(1, "");
            return AjaxObject.error(e.getMessage());
        }
    }

    @RequestMapping(value = "/getMemberConsumeInfo", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getMemberInfo(HttpServletRequest request, HttpServletResponse response,
                                    @RequestParam int vid, @RequestParam int mid) {
        try {
            VO vo = userService.getMemberInfo(vid, mid);
            return AjaxObject.ok().put("data", vo.toHashMap(true));
        } catch (Exception e) {
            logger.error("getMemberInfo Exception：", e);
            return AjaxObject.error("getMemberInfo Exception" + e.getMessage());
        }
    }
}
